package com.uade.tp3.g06;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;

public class UserCreator extends Activity {
	public static final String PREFS_NAME = "PrefsFile";
	public static final String SERVICE_CREATE_USER = "http://ecancha.com.ar/ws.php?modulo=usuarios&action=insert&nro=";
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.usercreator);
    }
    
    public void CreateUser(View v) {
    	SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    	SharedPreferences.Editor editor = settings.edit();
    	
    	String celular = ((EditText) findViewById(R.id.etCelular)).getText().toString();
    	String nombre = ((EditText) findViewById(R.id.etNombre)).getText().toString();
    	String apellido = ((EditText) findViewById(R.id.etApellido)).getText().toString();
    	
        editor.putString("celular", celular);
        editor.commit();

        Toast.makeText(UserCreator.this, SERVICE_CREATE_USER + celular + "&nombre=" + nombre + "&apellido=" + apellido, Toast.LENGTH_LONG).show();

    }
    
    public void ClearForm(View v) {
    	ViewGroup grupo = (ViewGroup)findViewById(R.id.NewUserGroup);
    	for (int i = 0, c = grupo.getChildCount(); i < c; ++i) {
    	    View view = grupo.getChildAt(i);
    	    if (view instanceof EditText) {
    	        ((EditText)view).setText("");
    	    }
    	}
    }
}
